/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.com.ces4.produccion.client;

import co.com.ces4.produccion.client.loging.Login;
import co.com.ces4.produccion.client.loging.PrincipalMenu;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootPanel;
import com.smartgwt.client.util.BooleanCallback;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Dialog;

/**
 * Main entry point.
 *
 * @author Sebastian
 */
public class SoftproEntryPoint implements EntryPoint {

    /** 
     * Creates a new instance of MainEntryPoint
     */
    public SoftproEntryPoint() {
    }

    /** 
     * The entry point method, called automatically by loading a module
     * that declares an implementing class as an entry-point
     */
    @Override
    public void onModuleLoad() {
        getAutenticacionService().validarSesion(new AsyncCallback<Boolean>() {

            public void onFailure(Throwable caught) {
                SC.warn("Error", caught.getMessage(), new BooleanCallback() {

                    @Override
                    public void execute(Boolean value) {
                    }
                }, new Dialog());
            }

            public void onSuccess(Boolean result) {
                if (result) {
                    PrincipalMenu ppalMenu = new PrincipalMenu();
                } else {
                    Login l = new Login();
                    RootPanel.get().add(l);
                    RootPanel.get().setStyleName("colorFondo");
                }
            }
        });

    }

    public AutenticacionServiceAsync getAutenticacionService() {
        return GWT.create(AutenticacionService.class);
    }
}
